class Admin::ProjectsController < ApplicationController
  def new
    @page_title = 'Create new project'
    @project = Project.new  
  end

  def create
    @project = Project.new(params[:project])
    if @project.save
      flash[:notice] = "Project #{@project.name} was successfully created."
    redirect_to :action => 'index'
    else
      @page_title = 'Create new project'
      render :action => 'new'
    end
  end

  def edit
    @project = Project.find(params[:id])
    @page_title = 'Edit project'
  end

  def update
    @project = Project.find(params[:id])
    if @project.update_attributes(params[:project])
      flash[:notice] = "project #{@project.name} was successfully updated."
    redirect_to :action => 'show', :id => @project.id
    else
      @page_title = 'Edit project'
      render :action => 'edit'
    end
  end

  def destroy
    @project = Project.find(params[:id])
    flash[:notice] = "Successfully deleted project #{@project.name}"
    @project.destroy
    redirect_to :action => 'index'
  end

  def show
    @project = Project.find(params[:id])
    @page_title = @project.name
  end

  def index
    @projects = Project.find(:all)
    @page_title = 'Listing projects'
  end

end
